package com.example.grade;

import java.util.*;

public class Student {
    private final String id;      // 学号
    private final String name;    // 姓名
    private final String clazz;   // 班级

    public Student(String id, String name, String clazz) {
    	if (id == null || id.trim().isEmpty()) 
    		throw new IllegalArgumentException("学号不能为空");
    	if (name == null || name.trim().isEmpty())
            throw new IllegalArgumentException("姓名不能为空");
        if (clazz == null || clazz.trim().isEmpty())
            throw new IllegalArgumentException("班级不能为空");
    	this.id = id;
        this.name = name;
        this.clazz = clazz;
    }

    public String getId()   { return id; }
    public String getName() { return name; }
    public String getClazz(){ return clazz; }

    @Override
    public String toString() {
        return String.format("Student{id='%s', name='%s', class='%s'}", id, name, clazz);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Student)) return false;
        return id.equals(((Student) o).id);
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }
}